<template>
	<view class="address row bg-white">
	    <image class="icon-md mr20" src="/static/images/icon_address.png"></image>
	    <view class="flex1 mr20">
	        <view class="black md" v-if="!address.business_name && isSelect">选择自提点</view>
	        <view v-else>
	            <text class="name md mr10">{{address.business_name}}</text>
	            <text class="distance md mr10">距离：{{distance(address.lat,address.lng)}}km</text>
	            <view class="area sm mt10 lighter">
	                {{address.province}} {{address.city}} {{address.district}} {{address.address}}
	            </view>
	        </view>
	    </view>
	    <image v-if="isSelect" class="icon-sm" src="/static/images/arrow_right.png"></image>
	</view>
</template>

<script>
	export default {
		props:{
			isSelect: {
				type: Boolean,
				default: true
			},
			address: {
				type: [Object, Array],
				default: () => ({})
			}
		},
		data() {
			return {
				
			};
		},
		methods:{
			//根据经纬度计算距离
			distance(lat1, lng1) {
				let location = uni.getStorageSync('location')
				let lat2 = location.latitude;
				let lng2 = location.longitude;
				let rad1 = parseFloat(lat1) * Math.PI / 180.0;
				let rad2 = parseFloat(lat2) * Math.PI / 180.0;
				let a = rad1 - rad2;
				let b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
			
				let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(rad1) * Math.cos(
				rad2) * Math.pow(Math.sin(b / 2), 2)));
				s = s * 6378.137;
				s = Math.round(s * 10000) / 10000;
				s = s.toString();
				s = s.substring(0, s.indexOf('.') + 2);
				return s; //返回距离
			},
		}
	}
</script>

<style lang="scss">
.address {
    min-height: 164rpx;
    padding: 0 24rpx;
	border-radius: 14rpx;
	margin: 20rpx 20rpx 0;
}

</style>
